package com.rstrulak.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.rstrulak.core.dao.GenericDaoImpl;
import com.rstrulak.model.User;

@Repository("userDao")
public class UserDaoImpl extends GenericDaoImpl<User, Long> implements UserDao {

	@Override
	public User getUserByLastName(String lastName) {
		DetachedCriteria criteria = createDetachedCriteria();
		criteria.add(Restrictions.eq("lastName", lastName));
		return getObjectByCriteria(criteria);
	}

	@Override
	public User getUserByLogin(String login) {
		return getObjectByCriteria(createDetachedCriteria().add(Restrictions.eq(User.LOGIN, login)));
	}

	@Override
	public List<User> getAllUsersExceptUser(List<Long> userIdList) {
		DetachedCriteria criteria = createDetachedCriteria();
		criteria.add(Restrictions.not(Restrictions.in("id", userIdList)));
		return getListByCriteria(criteria);
	}

}
